/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.opmviewer.valueproviders;

import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.*;
import com.hp.hpl.jena.util.FileManager;
import java.io.InputStream;

/**
 *
 * @author grzegorz
 */
public class JanusValueProvider implements ValueProvider {

    private Model model;

    public JanusValueProvider(String janusFileName) {
        // create an empty model
        model = ModelFactory.createDefaultModel();

        // use the FileManager to find the input file
        InputStream in = FileManager.get().open(janusFileName);
        if (in == null) {
            throw new IllegalArgumentException(
                    "File: " + janusFileName + " not found");
        }

        // read the RDF/XML file
        model.read(in, null);

    }

    public Value getValue(String artifactURI) {
        Value v = new Value();

        Resource res = model.getResource(artifactURI);
        Literal val = (Literal) res.getProperty(RDFS.comment).getObject();
        String type = val.getDatatypeURI();
        v.setType(getType(type));
        v.setValue(val.getString());
        return v;
    }

    private ValueType getType(String type){
        return ValueType.STRING;
    }

}
